//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _VIEWATTRIBUTES_H
#define _VIEWATTRIBUTES_H
#include <common/identified.h>
#include <model/particletemplate_fwd.h>
#include "viewattribute.h"
#include "viewattributegroup.h"
//
namespace ViewAttributeType
{
//
/*template<class T>
class Object:public ViewAttribute
{
public:
   static T *lookup(ViewAttributeGroup *group,ViewAttributeName name)
   {
      return static_cast<T*>(group->get_attribute(name));
   }
//construction
public:
   Object(ViewAttributeGroup *p_container,ViewAttributeName p_name);
//disabled
private:
   Object(const Object<T>&);
   Object &operator=(const Object<T>&);
//data access
public:
   T *get_obj() const
      {return object;}
   void set_obj(T *obj,View *origin)
      {object=obj; emit_value_changed(origin);}
//data
private:
   T *object;
//implementation
private:
   void handle_doc_event_pre_view(const DocEvent *evnt);
};
//*/
class ModelDataObject:public ViewAttribute
{
public:
   static inline ModelDataObject *lookup(const QSharedPointer<ViewAttributeGroup> &group,ViewAttributeName name);
//construction
public:
   ModelDataObject(const QSharedPointer<ViewAttributeGroup> &p_container,ViewAttributeName p_name);
//disabled
private:
   ModelDataObject(const ModelDataObject&);
   ModelDataObject &operator=(const ModelDataObject&);
//data access
public:
   Identified *get_object() const
      {return object;}
   inline void set_object(Identified *obj,View *origin=0)
      {object=obj;object_id=obj?obj->get_id():Id();emit_value_changed(origin);}
//data
private:
   Identified *object;
   Id object_id;
//implementation
private:
   void handle_post_primitive_pre_view(const Primitive &prim);
};
//inline functions
inline ModelDataObject *ModelDataObject::lookup(const QSharedPointer<ViewAttributeGroup> &group,ViewAttributeName name)
{
   return static_cast<ModelDataObject*>(group->get_attribute(name));
}
//
class PTTimeMark:public ViewAttribute
{
public:
   static inline PTTimeMark *lookup(const QSharedPointer<ViewAttributeGroup> &group,ViewAttributeName name);
//construction
public:
   PTTimeMark(const QSharedPointer<ViewAttributeGroup> &p_container,ViewAttributeName p_name);
//disabled
private:
   PTTimeMark(const PTTimeMark&);
   PTTimeMark &operator=(const PTTimeMark&);
//data access
public:
   inline model::ParticleTemplate *get_particle_template() const
      {return particle_template;}
   void set_particle_template(model::ParticleTemplate *p_particle_template,QString p_tm_name,View *origin=0);
   inline const QString &get_tm_name() const
      {return tm_name;}
   void set_tm_name(const QString &p_tm_name,View *origin=0);
//data
private:
   model::ParticleTemplate *particle_template;
   Id id;
   QString tm_name;
//implementation
private:
   void handle_post_primitive_pre_view(const Primitive &prim);
};
//inline functions
inline PTTimeMark *PTTimeMark::lookup(const QSharedPointer<ViewAttributeGroup> &group,ViewAttributeName name)
{
   return static_cast<PTTimeMark*>(group->get_attribute(name));
};
//
}
#endif
